<?php
/**
 * 商家注销
 *
 *
 *
 *
 * @copyright  Copyright (c) 2007-2015 ShopNC Inc. (http://www.shopnc.net)
 * @license    http://www.shopnc.net
 * @link       http://www.shopnc.net
 * @since      File available since Release v1.1
 */



defined('ByShopWWI') or exit('Access Invalid!');

class seller_applyControl extends mobileMemberControl {

    public function __construct(){
        parent::__construct();
    }

    /**
     * 店铺信息
     */
    public function save_infoOp() {
		
	
       if(!empty($_POST)) {
		  // $_POST['store_class_ids']=array( $_POST['store_class_ids']);
		if(!empty($_POST['store_class_ids'])) {
			//  $_POST['store_class_ids'] ='{"0"="1,4,18","1"="1,4,18"}';
			$str=$_POST['store_class_ids'];
			$str= rtrim($str, "}");
   
			$str= ltrim($str, "{");

			$ss=explode('","',$str);
			$aa=array();
			foreach($ss as $key=>$row){
				$rows = strstr($row, ':');
				$rows = ltrim($rows, ':"');
				$rows= rtrim($rows, '"');
				$aa[]=$rows;
			}
			$_POST['store_class_ids']=$aa;
            foreach ($_POST['store_class_ids'] as $value) {
                $store_class_ids[] = $value;
            }
        }
		
        if(!empty($_POST['store_class_names'])) {
			
			//$_POST['store_class_ids'] ='{"0"="1,4,18","1"="1,4,18"}';
			$str=$_POST['store_class_names'];
			$str= rtrim($str, "}");
			$str= ltrim($str, "{");
			$ss=explode('","',$str);
			$aa=array();
			foreach($ss as $key=>$row){
				$rows = strstr($row, ':');
				$rows = ltrim($rows, ':"');
				$rows= rtrim($rows, '"');
				$aa[]=$rows;
			}
			$_POST['store_class_names']=$aa;
		
            foreach ($_POST['store_class_names'] as $value) {
                $store_class_names[] = $value;
            }
        }
		  // die;
            $param = array();
            $param['member_name'] = $this->member_info['member_name'];   
            $param['company_name'] = $_POST['company_name'];
            $param['company_address'] = $_POST['company_address'];
            $param['company_address_detail'] = $_POST['company_address_detail'];//详细地址
            $param['contacts_name'] = $_POST['contacts_name'];//联系人
            $param['contacts_phone'] = $_POST['contacts_phone'];
            $param['contacts_email'] = $_POST['contacts_email'];
            $param['business_licence_number'] = $_POST['business_licence_number'];
            $param['business_sphere'] = $_POST['business_sphere'];//姓名
			$param['business_licence_number_elc'] = $_POST['business_licence_number_elc'];
			$param['general_taxpayer'] = $_POST['general_taxpayer'];
            //$param['business_licence_number_elc'] = $this->upload_image('business_licence_number_elc');//省份证
           // $param['general_taxpayer'] = $this->upload_image('general_taxpayer');
			//支付宝
			$param['settlement_bank_account_name'] = $_POST['settlement_bank_account_name'];
            $param['settlement_bank_account_number'] = $_POST['settlement_bank_account_number'];
			$param['seller_name'] = $_POST['seller_name'];
			$param['store_name'] = $_POST['store_name'];
			$param['sc_name'] = $_POST['sc_name'];
			$param['sc_id'] = $_POST['sc_id'];
			$param['store_class_ids'] = serialize($store_class_ids);
			$param['store_class_names'] = serialize($store_class_names);
			$param['joinin_year'] = intval($_POST['joinin_year']);
			$param['joinin_state'] = $_POST['sg_id'];//等级
            $model_store_joinin = Model('store_joinin');
            $joinin_info = $model_store_joinin->getOne(array('member_id' => $this->member_info['member_id']));
            if(empty($joinin_info)) {
                $param['member_id'] = $this->member_info['member_id'];   
               $model_store_joinin->save($param);
			   output_data('您的申请已提交');
            } else {
				output_error('您已经申请过来');
            }
        }
        output_data('1');
    }
	function upload_imageOp(){
		header('Content-type: text/html; charset=UTF-8');
		
		$base64 = $_POST["business_image"]; // 得到参数
		$img = base64_decode($base64); // 将格式为base64的字符串解码
		$name = sprintf('%010d',time() - 946656000). sprintf('%03d', microtime() * 1000). sprintf('%04d', mt_rand(0,9999));

		$path = "../data/upload/shop/store_joinin/".$name.".jpg"; // 产生随机唯一的名字作为文件名
		file_put_contents($path, $img); // 将图片保存到相应位置*/
		$data['business_image'] = $name.'.jpg';
		output_data($data);
	}
	public function shop_levelOp(){
		//店铺等级
		$grade_list = rkcache('store_grade',true);
		//附加功能
		if(!empty($grade_list) && is_array($grade_list)){
			foreach($grade_list as $key=>$grade){
				$sg_function = explode('|',$grade['sg_function']);
				if (!empty($sg_function[0]) && is_array($sg_function)){
					foreach ($sg_function as $key1=>$value){
						if ($value == 'editor_multimedia'){
							$grade_list[$key]['function_str'] .= '富文本编辑器';
						}
					}
				}else {
					$grade_list[$key]['function_str'] = '无';
				}
			}
		}
		$grade_lists=array();
		foreach($grade_list as $value){
			$grade_lists[]=$value;
		}
		output_data($grade_lists);//Tpl::output('grade_list', $grade_list);
	}
	public function shop_classOp(){
		 //店铺分类
        $model_store = Model('store_class');
        $store_class = $model_store->getStoreClassList(array(),'',false);
        output_data($store_class);//Tpl::output('store_class', $store_class);
	}
	public function goods_classOp(){
		 //商品分类
        $gc	= Model('goods_class');
		$id=$_POST['gc_id'];
		if(empty($id)){
			$id=0;
		}
        $gc_list	= $gc->getGoodsClassListByParentId($id);
        output_data($gc_list);//Tpl::output('gc_list',$gc_list);
	}
    /**
     * 编辑店铺
     */
   /* public function store_editOp() {
		
		
		//商品分类
        $gc	= Model('goods_class');
        $gc_list	= $gc->getGoodsClassListByParentId(0);
        Tpl::output('gc_list',$gc_list);

		//店铺等级
		$grade_list = rkcache('store_grade',true);
		
		 $model_store = Model('store_class');
        $store_class = $model_store->getStoreClassList(array(),'',false);
		
        $upload = new UploadFile();
        /**
         * 上传店铺图片
        */
      /*  if (!empty($_FILES['store_banner']['name'])){
            $upload->set('default_dir', ATTACH_STORE);
            $upload->set('thumb_ext',   '');
            $upload->set('file_name','');
            $upload->set('ifremove',false);
            $result = $upload->upfile('store_banner');
            if ($result){
                $_POST['store_banner'] = $upload->file_name;
            }else {
                showDialog($upload->error);
            }
        }
        
        //删除旧店铺图片
        if (!empty($_POST['store_banner']) && !empty($store_info['store_banner'])){
            @unlink(BASE_UPLOAD_PATH.DS.ATTACH_STORE.DS.$this->store_info['store_banner']);
        }
        /**
         * 更新入库
         */
        /*$param = array(
            'store_banner' => empty($_POST['store_banner']) ? $this->store_info['store_banner'] : $_POST['store_banner'],
            'store_qq' => $_POST['store_qq'],
            'store_ww' => $_POST['store_ww'],
            'store_phone' => $_POST['store_phone'],
            'store_zy' => $_POST['store_zy'],
            'store_keywords' => $_POST['seo_keywords'],
            'store_description' => $_POST['seo_description']
        );

        $result = Model('store')->editStore($param, array('store_id' => $this->store_info['store_id']));
        if(!$result) {
            output_error('编辑失败');
        }
        output_data('1');
    }

    /**
     * 店铺信息统计
     */
   /* public function store_statisticsOp() {
        $model_stat = Model('stat');
        $start_time = strtotime(date('Y-m',time()));        // 当月开始
        // 月销量 月订单
        $condition = array();
        $condition['order_add_time'] = array('gt',$start_time);
        $monthly_sales = $model_stat->getoneByStatorder($condition, 'COUNT(*) as ordernum,SUM(order_amount) as orderamount ');
        
        // 月访问量
        //确定统计分表名称
        $last_num = $this->store_info['store_id'] % 10; //获取店铺ID的末位数字
        $tablenum = ($t = intval(C('flowstat_tablenum'))) > 1 ? $t : 1; //处理流量统计记录表数量
        $flow_tablename = ($t = ($last_num % $tablenum)) > 0 ? "flowstat_$t" : 'flowstat';
        $condition = array();
        $condition['store_id'] = $this->store_info['store_id'];
        $condition['stattime'] = array('gt', $start_time);
        $condition['type'] = 'sum';
        $statlist_tmp = $model_stat->getoneByFlowstat($flow_tablename, $condition, 'SUM(clicknum) as amount');
        
        $output = array(
            'store_name'    => $this->store_info['store_name'],
            'store_banner'  => getStoreLogo($this->store_info['store_banner'], 'store_logo'),
            'order_amount'  => $monthly_sales['orderamount'],
            'order_num'     => $monthly_sales['ordernum'],
            'click_amount'  => $statlist_tmp['amount']
        );

        output_data(array('statistics' => $output));
    }*/
}
